<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-区域区域"
		width="800px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="110px" :show-message="false">
			<el-row ref="box1">
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="区域">
						<span class="read-only-2">{{ ruleForm.workshopName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="区域编号">
						<span class="read-only-2">{{ ruleForm.code }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item class="margin-bottom-10" label="区域名称">
						<span class="read-only-2">{{ ruleForm.name }}</span>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<jk-table border :data="ruleForm.processList" :height="dialogTableHeight - 20">
			<vxe-column title="工序" align="center" field="processName" :width="140"></vxe-column>
			<vxe-column title="机台明细" align="left" field="shiftName" :min-width="100">
				<template slot-scope="scope">
					<div class="flex-start-center-wrap">
						<div
							v-for="(item, index) in scope.row.machineList"
							:key="index"
							style="width: calc(100% / 6);padding: 1px;"
						>
							<el-tag class="width-100-percent flex-between-center" effect="plain" @close="ruleForm.processList[scope.rowIndex].machineList.splice(index, 1)">
								<span>{{ item.machineName }}</span>
							</el-tag>
						</div>
					</div>
				</template>
			</vxe-column>
		</jk-table>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { spinWorkshopAreaGet } from '../../../api/basicData/workshopArea';
    export default {
        name: 'WorkshopArea',
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                showLoading: true,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return spinWorkshopAreaGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
